﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZOVNP.Model.Abstracts;

namespace ZOVNP.WinView
{
    public partial class MaterialEditControl : UserControl
    {
        private IMaterial _material;

        public MaterialEditControl(IMaterial material)
        {
            Material = material;
            InitializeComponent();
        }

        public IMaterial Material
        {
            get { return _material; }
            set
            {
                _material = value;

                tbxName.Text = _material != null ? _material.Name : string.Empty;
                tbxDescription.Text = _material != null ? _material.Description : string.Empty;
            }
        }

        private void tbxName_TextChanged(object sender, EventArgs e)
        {
            if (_material == null)
                throw new InvalidOperationException();

            _material.Name = tbxName.Text;
        }

        private void tbxDescription_TextChanged(object sender, EventArgs e)
        {
            if (_material == null)
                throw new InvalidOperationException();

            _material.Description = tbxDescription.Text;
        }
    }
}
